var _ajax = require('../../utils/ajax');
var _Server = require('../../utils/server');
var WxParse = require('../../wxParse/wxParse'); // 富文本转化插件
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this;
        _ajax.myProductDetails(options.productId, function(data) {
            if (data.code == 0) {
                that.setData({
                    indexUrl: _Server.url,
                    myProductData: data.data,
                    courseId: options.courseId,
                });
                var article = data.data.content;
                WxParse.wxParse('article', 'html', article, that, 5);
            }
        }, this);
    },
    fnGoBuy: function(e) {
        var that = this;
        _ajax.myProductPayOrder(that.data.courseId, that.data.myProductData.product_id, function(data) {
            if (data.code == 0) {
                wx.navigateTo({
                    url: '../wxPayProduct/wxPayProduct?orderId=' + data.data.order_id + '&productId=' + that.data.myProductData.product_id,
                });
            } else {
                setTimeout(function () {
                    wx.showToast({
                        title: data.msg,
                        icon: 'none'
                    });
                }, 500);
            }
        }, this);
    },
})